//
//  JYMineController.m
//  JYShop
//
//  Created by 花花 on 2017/9/28.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "JYMineController.h"
#import "JYMineMenuCell.h"
#import "JYMineHeaderView.h"
#import "JYWalletViewController.h"
#import "JYSettingController.h"
#import "JYServiceController.h"
#import "JYAddressController.h"
#import "JYOrderController.h"
#import "JYCODController.h"
@interface JYMineController ()
@property(nonatomic)NSArray *titleArr;
@property(nonatomic)NSArray *imgArr;
@end
@implementation JYMineController

#pragma mark - Life Cycle
- (void)viewDidLoad {
    [super viewDidLoad];

    [self initUI];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
 
    [self.navigationController setNavigationBarHidden:YES];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

#pragma mark - initUI
- (void)initUI{

    self.titleArr = @[@[@"我的钱包",@"货到付款"],@[@"收货地址",@"联系客服",@"设置"]];
    self.imgArr = @[@[@"mine_purse",@"mine_cash_on_delivery"],@[@"mine_address",@"mine_customer_service",@"mine_setting"]];
    self.tableView.tableHeaderView = [[JYMineHeaderView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 200)];
    self.tableView.tableFooterView = [UIView new];

}
#pragma mark - <UITableViewDataSource,UITableViewDelegate>
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (section == 0) {
        return 0;
    }else if(section == 1){
     return [self.titleArr[0] count];
    }
    return [self.titleArr[1] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    JYMineMenuCell *cell = [JYMineMenuCell cellWithTableView:tableView];
    
    if (indexPath.section == 1) {
        cell.titleLabel.text = [self.titleArr[0] safeObjectAtIndex:indexPath.row];
        cell.iconImage.image =[UIImage imageNamed:[self.imgArr[0] safeObjectAtIndex:indexPath.row]];
        if (indexPath.row == 0) {
            
            cell.subMoenyLabel.text = [NSString stringWithFormat:@"美点余额：%@元",[[NSUserDefaults standardUserDefaults] objectForKey:kFreeCash]];
        }
    }else{
        cell.titleLabel.text = [self.titleArr[1] safeObjectAtIndex:indexPath.row];
        cell.iconImage.image =[UIImage imageNamed:[self.imgArr[1] safeObjectAtIndex:indexPath.row]];
    }
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    if (section == 0) {
        JKFuncationView *headerView = [[JKFuncationView alloc]initWithFrame:CGRectMake(0, 0, Screen_Width, 60)];
        headerView.handlerBtnOnClick = ^(JYOrderType type){
            NSLog(@"%zd",type);
            [self funcationBtnOnClick:type];
        };
        return headerView;
    }
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
        [self.navigationController pushViewController:[JYWalletViewController new] animated:YES];
        }else{
            [self.navigationController pushViewController:[JYCODController new] animated:YES];
        }
    }else  if (indexPath.section  == 2) {
        if (indexPath.row == 0) {

            [self.navigationController pushViewController:[JYAddressController new] animated:YES];
        }else if (indexPath.row == 1) {
            
            [self.navigationController pushViewController:[JYServiceController new] animated:YES];
        }else if (indexPath.row == 2) {
            [self.navigationController pushViewController:[JYSettingController new] animated:YES];
        }
    }

}
- (void)funcationBtnOnClick:(JYOrderType )type{
    
    
      JYOrderController *orderVc =   [JYOrderController new];
    
       orderVc.index = type;
        [self.navigationController pushViewController:orderVc animated:YES];


}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
    return 60;
    }
    return 10;
}
@end
